﻿/// <reference path="jquery-2.1.4.min.js" />
/// <reference path="createjs.js" />

var bgW = $(window).width();
bgW = 640;
var bgH = $(window).height();

var stage = new createjs.Stage("gameView");
stage.enableMouseOver(20);
var Container0 = new createjs.Container;
var Container1 = new createjs.Container;
var Container2 = new createjs.Container;
var imgContainer = new createjs.Container;
var imgnewContainer = new createjs.Container;
var queue = new createjs.LoadQueue();
createjs.Sound.alternateExtensions = ["mp3,wav"];
queue.installPlugin(createjs.Sound);
var LoadCanvas = function() {

	/////////////////////////启动触摸
	createjs.Touch.enable(stage);
	queue.loadManifest([
		{id:"img_huatu_kuang",src:"img_huatu/img_huatu_kuang.png"},
		{id:"waikuang",src:"img_huatu/waikuang.png"},
		{id:"img_huatu_hua1",src:"img_huatu/img_huatu_hua1.png"},
		{id:"img_huatu_hua2",src:"img_huatu/img_huatu_hua2.png"},
		{id:"img_huatu_hua3",src:"img_huatu/img_huatu_hua3.png"},
		{id:"img_huatu_hua4",src:"img_huatu/img_huatu_hua4.png"},
		{id:"img_huatu_wenan1",src:"img_huatu/img_huatu_wenan1.png"},
		{id:"img_huatu_wenan2",src:"img_huatu/img_huatu_wenan2.png"},
		{id:"img_huatu_wenan3",src:"img_huatu/img_huatu_wenan3.png"},
		{id:"img_huatu_wenan4",src:"img_huatu/img_huatu_wenan4.png"},
		{id:"kuang",src:"img_huatu/kuang.png"},
		{id:"logo_dianshiguo",src:"img_huatu/logo_dianshiguo.png"},
//	], true, "http://jkera2016.oss-cn-shanghai.aliyuncs.com/mingxinpian/");
	], true, "image/");
	queue.on("progress", function(event) {

		if (queue.progress.toString().length > 4) {
			progress = queue.progress.toString().substr(2, 2);
		} else {
			if (queue.progress.toString().length == 3 || queue.progress.toString().length == 4) {
				progress = queue.progress * 100;
			}

			progress = queue.progress;
		}
		if (progress.toString().indexOf(".") <= 0) {
			if (progress == "00") {
				progress = "0";
			}
			//          baifenbi.text = progress + "%";
			if (progress == "1") {
				progress = "100";
				$(".loading").css("display", "none");
//				$(".loading,.img2_bg").css("display", "none");
			}
			$(".jindutiao").html(progress + "%");
//			console.log(progress);
		}

	});
	queue.on("complete", handleComplete, this);
}
//var bg,logo1,logo2;
var handleComplete = function() {
//	alert(rukou);
//	alert("版本号：jsv6");
	//Load1();
	createjs.Ticker.setFPS(60);
	createjs.Ticker.addEventListener("tick", function(event) {
		stage.update();
	})
	
}

var Load1 = function(){
	var kuang = new createjs.Bitmap(queue.getResult("kuang"));
	var waikuang = new createjs.Bitmap(queue.getResult("waikuang"));
//  shape.graphics.beginFill("#fffaf0").drawRect(0,0,bgW,bgH);
	var img_huatu_kuang = new createjs.Bitmap(queue.getResult("img_huatu_kuang"));
	img_huatu_kuang.x = 0 ;img_huatu_kuang.y = 0;
	var wenan = new createjs.Bitmap(queue.getResult("img_huatu_wenan"+type_index));
	wenan.x = 70 ;wenan.y = 467;
	wenan.alpha = 0;
	var hua = new createjs.Bitmap(queue.getResult("img_huatu_hua"+type_index));
	hua.x = 40 ;hua.y = 50;
	var logo_dianshiguo = new createjs.Bitmap(queue.getResult("logo_dianshiguo"));
	var x,y;
	if(type_index==1){x=42;y=235};
	if(type_index==2){x=42;y=235};
	if(type_index==3){x=42;y=235};
	if(type_index==4){x=212;y=180};

	logo_dianshiguo.regX = logo_dianshiguo.getBounds().width >> 1;
	logo_dianshiguo.regY = logo_dianshiguo.getBounds().height >> 1;
	logo_dianshiguo.x = x + logo_dianshiguo.getBounds().width/2;logo_dianshiguo.y = y + logo_dianshiguo.getBounds().height/2;
	var shijian = 500;
	//createjs.Tween.get(logo_dianshiguo,{loop:true}).to({scaleX:0.5,scaleY:0.5},shijian).to({scaleX:1,scaleY:1},shijian);
	createjs.Tween.get(logo_dianshiguo,{loop:true}).to({alpha:1,rotation:0},shijian).to({alpha:0.5,rotation:360},shijian).to({alpha:1,rotation:0},shijian);
	stage.addChild(img_huatu_kuang,hua,logo_dianshiguo,Container1,waikuang,wenan);
	
    var drawingCanvas = new createjs.Shape;
//  drawingCanvas.graphics.beginFill("#365632").drawRect(0,0,bgW,bgH);
	Container1.addChild(drawingCanvas,kuang);
	
	var fontSize=10,oldx,oldy;
	Container1.addEventListener("mousedown",function(ev){
        oldx = ev.stageX;oldy = ev.stageY;
	})
	Container1.addEventListener("pressmove" , function(ev){
        drawingCanvas.graphics.setStrokeStyle(fontSize,'round').beginStroke(color).moveTo(oldx, oldy).lineTo(ev.stageX, ev.stageY);
//      drawingCanvas.graphics.setStrokeStyle(fontSize,'round').beginStroke("#fffaf0").moveTo(ev.stageX, ev.stageY).lineTo(oldx, oldy);
        oldx = ev.stageX;oldy = ev.stageY;
        console.log(oldx);
	});
	
	$(".draw_btn_over").click(function(){
		wenan.alpha = 1;
		setTimeout(function(){
			var imgsrc = document.getElementById("gameView").toDataURL("image/png","0.92");
			var sczp = document.getElementById("sczp");
			sczp.src = imgsrc;
			sczp.style.display = "block";
			$("#gameView,.draw_colors,.draw_btn_over_cancle").hide();
			$(".draw_btn_yaoqing_shuoming").show();
			$.post("shuju.php?jieshou=tijiaotupian",{openid:openid,xuhao:1,pic:imgsrc},function(text){
				try {
					var image1 = "http://www.jkera.cn/iqiyi_huatu/image/share.jpg";
					var url1 = "http://www.jkera.cn/iqiyi_huatu/fabu.html?id="+text;
					fenxiang("画图分享朋友主标题"+text,"画图分享朋友副标题", "画图分享朋友圈主标题", url1, image1, name);
				} catch(err) {
				}
			})
		},100)
		
	})
	$(".draw_btn_cancle").click(function(){
		drawingCanvas.graphics.clear()
	})
}















































































